﻿Public Class frmReImpresion

    Private Sub btnIngresar_Click(sender As Object, e As EventArgs) Handles btnBuscarN.Click

        If cbComprobante.SelectedIndex = 0 And checkB1Activar.Checked = False Then

            If buscarIDArriendo(txtNum.Text, cbComprobante.SelectedIndex) Then
                  Dim frmVisor As New frmVisorDePago
                frmVisor.idPago = CInt(txtNum.Text)
                frmVisor.Show()
            Else
                MessageBox.Show("El numero de ingreso no existe.", msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If

        ElseIf cbComprobante.SelectedIndex = 1 And checkB1Activar.Checked = False Then

            If buscarIDArriendo(txtNum.Text, cbComprobante.SelectedIndex) Then
                Dim frmVisor As New frmVisorDePagoArriendo
                frmVisor.idPago = CInt(txtNum.Text)
                frmVisor.Show()
            Else
                MessageBox.Show("El numero de ingreso no existe.", msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If
        ElseIf cbComprobante.SelectedIndex = 0 And checkB1Activar.Checked Then

            If buscarIDArriendo(CInt(txtNum.Text), CInt(txtNum2.Text), cbComprobante.SelectedIndex) Then
                Dim frmVisor As New frmVisorBusRangoID
                frmVisor.vidPagoID = CInt(txtNum.Text)
                frmVisor.vidPagoID2 = CInt(txtNum2.Text)
                frmVisor.Show()
            Else
                MessageBox.Show("El numero de ingreso no existe en el rango indicado.", msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)


            End If

        ElseIf cbComprobante.SelectedIndex = 1 And checkB1Activar.Checked Then

            If buscarIDArriendo(CInt(txtNum.Text), CInt(txtNum2.Text), cbComprobante.SelectedIndex) Then
                Dim frmVisor As New frmVisorBusARangoID
                frmVisor.aidPagoID = CInt(txtNum.Text)
                frmVisor.aidPagoID2 = CInt(txtNum2.Text)
                frmVisor.Show()
            Else
                MessageBox.Show("El numero de ingreso no existe en el rango indicado.", msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)


            End If

        End If

    End Sub



    Private Sub checkB1Activar_CheckedChanged(sender As Object, e As EventArgs) Handles checkB1Activar.CheckedChanged

        If checkB1Activar.Checked = False Then
            txtNum2.Enabled = False
            lblHastaN.Enabled = False
            txtNum2.Text = "0"

        Else
            txtNum2.Enabled = True
            lblHastaN.Enabled = True
        End If
    End Sub

    Private Sub checkB2Activar_CheckedChanged(sender As Object, e As EventArgs) Handles checkB2Activar.CheckedChanged
        If checkB2Activar.Checked = False Then
            dtpFecha2.Enabled = False
            lblHastaFecha.Enabled = False

        Else
            dtpFecha2.Enabled = True
            lblHastaFecha.Enabled = True
        End If
    End Sub

    Private Sub txtNum_GotFocus(sender As Object, e As EventArgs) Handles txtNum.GotFocus
        If txtNum.Text = "0" Then
            txtNum.Clear()
        End If
    End Sub

    Private Sub txtNum2_GotFocus(sender As Object, e As EventArgs) Handles txtNum2.GotFocus
        If txtNum2.Text = "0" Then
            txtNum2.Clear()
        End If
    End Sub

    Private Sub txtNum_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtNum.KeyPress
        If InStr(1, "0123456789,-" & Chr(8), e.KeyChar) = 0 Then
            e.KeyChar = ""
        End If
    End Sub


    Private Sub frmReImpresion_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cbComprobante.SelectedIndex = 0
        cbcomprobante2.SelectedIndex = 0
    End Sub

    Private Sub txtNum_LostFocus(sender As Object, e As EventArgs) Handles txtNum.LostFocus
        If txtNum.TextLength = 0 Then
            txtNum.Text = 0
        End If
    End Sub



    Private Sub txtNum2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtNum2.KeyPress
        If txtNum2.Text = "0" Then
            txtNum2.Clear()
        End If
    End Sub

    Private Sub txtNum2_LostFocus(sender As Object, e As EventArgs) Handles txtNum2.LostFocus
        Dim varCambio As Integer
        If txtNum2.TextLength = 0 Then
            txtNum2.Text = 0

        ElseIf CInt(txtNum.Text) > CInt(txtNum2.Text) Then
            varCambio = txtNum.Text
            txtNum.Text = txtNum2.Text
            txtNum2.Text = varCambio

        End If


    End Sub

    Private Sub btnBucarF_Click(sender As Object, e As EventArgs) Handles btnBucarF.Click

        If cbcomprobante2.SelectedIndex = 0 And checkB2Activar.Checked = False Then

            If buscarFechaArriendo(dtpFecha1.Value.ToShortDateString, cbcomprobante2.SelectedIndex) Then
                Dim frmVisor As New frmVisorBusGFecha
                frmVisor.fecidPago = dtpFecha1.Value.ToShortDateString
                frmVisor.Show()
            Else
                MessageBox.Show("En esta fecha no existe un ingreso.", msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If

        ElseIf cbcomprobante2.SelectedIndex = 1 And checkB2Activar.Checked = False Then

            If buscarFechaArriendo(dtpFecha1.Value.ToShortDateString, cbcomprobante2.SelectedIndex) Then
                Dim frmVisor As New frmVisorBusAFecha
                frmVisor.vidPago = dtpFecha1.Value.ToShortDateString
                frmVisor.Show()
            Else
                MessageBox.Show("En esta fecha no existe un ingreso.", msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If

        ElseIf cbcomprobante2.SelectedIndex = 1 And checkB2Activar.Checked Then

            If buscarFechaArriendo(dtpFecha1.Value.ToShortDateString, dtpFecha2.Value.ToShortDateString, cbcomprobante2.SelectedIndex) Then
                Dim frmVisor As New frmVisorBusARangoFecha
                frmVisor.vidPago = dtpFecha1.Value.ToShortDateString
                frmVisor.vidPago2 = dtpFecha2.Value.ToShortDateString
                frmVisor.Show()
            Else
                MessageBox.Show("En esta fecha no existe un ingreso.", msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If
           
        ElseIf cbcomprobante2.SelectedIndex = 0 And checkB2Activar.Checked Then

            If buscarFechaArriendo(dtpFecha1.Value.ToShortDateString, dtpFecha2.Value.ToShortDateString, cbcomprobante2.SelectedIndex) Then
                Dim frmVisor As New frmVisorBusGRangoFecha
                frmVisor.vidPagoFecha1 = dtpFecha1.Value.ToShortDateString
                frmVisor.vidPagoFecha2 = dtpFecha2.Value.ToShortDateString
                frmVisor.Show()
            Else
                MessageBox.Show("En esta fecha no existe un ingreso.", msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)

            End If

        End If
    End Sub


  

End Class